//
//  SISSCommentMidView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/8/2.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSCommentMidView.h"
#import "SISSRateBarView.h"

@interface SISSCommentMidView ()<SISSRateBarViewDelegate>

/// 评分Label
@property (weak, nonatomic) UILabel *gradeLabel;
/// 评分StarView
@property (weak, nonatomic) SISSRateBarView *gradeStarView;

/// 评语Label
@property (weak, nonatomic) UILabel *commentLabel;


@end
@implementation SISSCommentMidView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self initUI];
        [self initConstraint];
    }
    
    return self;
}

#pragma mark - SISSRateBarViewDelegate
- (void)rateBarViewDidSelectedRateBarView:(SISSRateBarView *)rateBarView atIndex:(NSInteger)index {
    rateBarView.rate = index;
    self.gradeStar = index;
}

#pragma mark - UI
- (void)initUI {
    
    UILabel *gradeLabel = [[UILabel alloc] init];
    gradeLabel.font = [UIFont systemFontOfSize:16];
    gradeLabel.textColor = MAIN_TEXT_COLOR;
    gradeLabel.text = @"评分：";
    [self addSubview:gradeLabel];
    self.gradeLabel = gradeLabel;
    
    SISSRateBarView *gradeView = [[SISSRateBarView alloc] init];
    gradeView.delegate = self;
    gradeView.starTintColor = [UIColor redColor];
    gradeView.tag = 100;
    [self addSubview:gradeView];
    self.gradeStarView = gradeView;
    
    UILabel *commentLabel = [[UILabel alloc] init];
    commentLabel.font = [UIFont systemFontOfSize:16];
    commentLabel.textColor = MAIN_TEXT_COLOR;
    commentLabel.text = @"评语：";
    [self addSubview:commentLabel];
    self.commentLabel = commentLabel;
    
    SISSTextView *commentTextView = [[SISSTextView alloc] init];
    commentTextView.layer.borderWidth = 1;
    commentTextView.placeholder = @"请输入评价，不要包含特殊字符。";
    commentTextView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    [self addSubview:commentTextView];
    self.commentTextView = commentTextView;
    
}

#pragma mark - 约束
- (void)initConstraint {
    WeakSelf
    CGFloat margin = 8.0;
    [self.gradeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(2 * margin);
        make.top.equalTo(weakSelf).offset(2 * margin);
    }];
    
    [self.gradeStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.gradeLabel.mas_right);
        make.centerY.equalTo(weakSelf.gradeLabel);
        make.size.mas_equalTo(CGSizeMake(200, 30));
    }];
    
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.gradeLabel);
        make.top.equalTo(weakSelf.gradeLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.commentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.commentLabel);
        make.top.equalTo(weakSelf.commentLabel.mas_bottom);
        make.right.equalTo(weakSelf).offset(-2 * margin);
        make.height.mas_equalTo(10 * margin);
        make.bottom.equalTo(weakSelf);
    }];
    
}


@end
